import random, time,queue
from multiprocessing.managers import BaseManager

# 发送任务
task_queue = queue.Queue()
# 接受任务
result_queue = queue.Queue()

class QueueManager(BaseManager):
    pass

QueueManager.register("get_task_queue", callable = lambda: task_queue)
QueueManager.register('get_result_queue',callable = lambda: result_queue)

manager = QueueManager(address=('',5000), authkey= b'abc')

manager.start()

task = manager.get_task_queue()
result = manager.get_result_queue()

for i in range(10):
    n = random.randint(0,1000)
    print('Put task %d....' %n)
    task.put(n)

# 从result队列读取结果:
print('Try get results...')
for i in range(10):
    r = result.get(timeout=100)
    print('Result: %s' % r)
# 关闭:
manager.shutdown()
print('master exit.')